/*
DigitalFlipbook Source Code License Agreement
Copyright(c) 2008 DigitalFlipbook. All rights reserved.
	
Please read this Source Code License Agreement carefully before using
the source code.
	
DigitalFlipbook grants to you a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable copyright license, to reproduce,
prepare derivative works of, publicly display, publicly perform, and
distribute this source code and such derivative works in source or
object code form without any attribution requirements.
	
The name "DigitalFlipbook" must not be used to endorse or promote products
derived from the source code without prior written permission.
	
You agree to indemnify, hold harmless and defend DigitalFlipbook from and
against any loss, damage, claims or lawsuits, including attorney's
fees that arise or result from your use or distribution of the source
code.
	
THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL DIGITALFLIPBOOK
OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.digitalflipbook.webapis.scribd
{
	import com.digitalflipbook.webapis.scribd.events.*;
	
	import flexunit.framework.Test;
	import flexunit.framework.TestCase;
	import flexunit.framework.TestSuite;

	public class ScribdServiceTest extends TestCase
	{
		private const CALL_TIMEOUT:int = 10000;
		
		/**
		*	You need to provide your own API keys here in order for the
		*	test to run.
		*
		*	http://www.scribd.com/platform/documentation/api
		*/		
		public static var API_KEY:String = "<API KEY>";
		public static var SECRET:String = "<SECRET>";
		
	    public function ScribdServiceTest( methodName:String )
	    {
			super( methodName );
        }
	
		public static function suite():TestSuite
		{
			var ts:TestSuite = new TestSuite();
			
			ts.addTest( Test( new ScribdServiceTest( "testAPIKey" ) ) );
			ts.addTest( Test( new ScribdServiceTest( "testSecret" ) ) );
			
			//*********************************************************
			// Test the "Docs" method group
			//*********************************************************
			// Not tested - need to have a valid api key to return successful result
			ts.addTest( Test( new ScribdServiceTest( "testDocsChangeSettings" ) ) );
			// Not tested - need to have a valid token to return successful result
			ts.addTest( Test( new ScribdServiceTest( "testDocsDelete" ) ) );
			// Not tested - need to have a valid token to return successful result
			ts.addTest( Test( new ScribdServiceTest( "testDocsGetConversionStatus" ) ) );
			// Not tested - need to have a valid token to return successful result
			ts.addTest( Test( new ScribdServiceTest( "testDocsGetList" ) ) );
			// Not tested - need to have a valid token to return successful result
			ts.addTest( Test( new ScribdServiceTest( "testDocsGetSettings" ) ) );
			// Not tested - need to have a valid token to return successful result
			ts.addTest( Test( new ScribdServiceTest( "testDocsSearch" ) ) );
			// Not tested - need to have a valid token to return successful result
			ts.addTest( Test( new ScribdServiceTest( "testDocsUpload" ) ) );
			// Not tested - need to have a valid token to return successful result
			ts.addTest( Test( new ScribdServiceTest( "testDocsUploadFromUrl" ) ) );
			
			//*********************************************************
			// Test the "User" method group
			//*********************************************************
			// Not tested - need to be authenticated to return successful result
			ts.addTest( Test( new ScribdServiceTest( "testUserLogin" ) ) );
			// Not tested - need to be authenticated to return successful result
			ts.addTest( Test( new ScribdServiceTest( "testUserSignup" ) ) );

			return ts;
		}
		
		public function testAPIKey():void
		{
			var service:ScribdService = new ScribdService( API_KEY );
		
			assertTrue( "service.api_key == API_KEY", service.api_key == API_KEY );
		}
		
		public function testSecret():void
		{
			var service:ScribdService = new ScribdService( API_KEY );
			service.secret = SECRET;
			assertTrue( "service.secret == SECRET", service.secret == SECRET );
		}

		//**************************************************************
		//
		// Tests for the "Docs" Method Group
		//
		//**************************************************************
		
		public function testDocsChangeSettings():void
		{
			var service:ScribdService = new ScribdService( API_KEY );
			service.secret = SECRET;
			service.addEventListener( ScribdResultEvent.DOCS_CHANGE_SETTINGS, 
									  addAsync( onDocsChangeSettings, CALL_TIMEOUT ) );
			service.docs.changeSettings( null );
		}
		
		private function onDocsChangeSettings( event:ScribdResultEvent ):void
		{
			assertTrue( "event.success == true", event.success );
		}
		
		public function testDocsDelete():void
		{
			var service:ScribdService = new ScribdService( API_KEY );
			service.secret = SECRET;
			service.addEventListener( ScribdResultEvent.DOCS_DELETE, 
									  addAsync( onDocsDelete, CALL_TIMEOUT ) );
			service.docs.deleteDoc( null );
		}
		
		private function onDocsDelete( event:ScribdResultEvent ):void
		{
			assertTrue( "event.success == true", event.success );
		}
		
		public function testDocsGetConversionStatus():void
		{
			var service:ScribdService = new ScribdService( API_KEY );
			service.secret = SECRET;
			service.addEventListener( ScribdResultEvent.DOCS_GET_CONVERSION_STATUS, 
									  addAsync( onDocsGetConversionStatus, CALL_TIMEOUT ) );
			service.docs.getConversionStatus( null );
		}
		
		private function onDocsGetConversionStatus( event:ScribdResultEvent ):void
		{
			assertTrue( "event.success == true", event.success );
		}
		
		public function testDocsGetList():void
		{
			var service:ScribdService = new ScribdService( API_KEY );
			service.secret = SECRET;
			service.addEventListener( ScribdResultEvent.DOCS_GET_LIST, 
									  addAsync( onDocsGetList, CALL_TIMEOUT ) );
			service.docs.getList();
		}
		
		private function onDocsGetList( event:ScribdResultEvent ):void
		{
			assertTrue( "event.success == true", event.success );
		}
		
		public function testDocsGetSettings():void
		{
			var service:ScribdService = new ScribdService( API_KEY );
			service.secret = SECRET;
			service.addEventListener( ScribdResultEvent.DOCS_GET_SETTINGS, 
									  addAsync( onDocsGetSettings, CALL_TIMEOUT ) );
			service.docs.getSettings( null );
		}
		
		private function onDocsGetSettings( event:ScribdResultEvent ):void
		{
			assertTrue( "event.success == true", event.success );
		}
		
		public function testDocsSearch():void
		{
			var service:ScribdService = new ScribdService( API_KEY );
			service.secret = SECRET;
			service.addEventListener( ScribdResultEvent.DOCS_SEARCH, 
									  addAsync( onDocsSearch, CALL_TIMEOUT ) );
			service.docs.search( null );
		}
		
		private function onDocsSearch( event:ScribdResultEvent ):void
		{
			assertTrue( "event.success == true", event.success );
		}
		
		public function testDocsUpload():void
		{
			var service:ScribdService = new ScribdService( API_KEY );
			service.secret = SECRET;
			service.addEventListener( ScribdResultEvent.DOCS_UPLOAD, 
									  addAsync( onDocsUpload, CALL_TIMEOUT ) );
			service.docs.upload( null );
		}
		
		private function onDocsUpload( event:ScribdResultEvent ):void
		{
			assertTrue( "event.success == true", event.success );
		}
		
		public function testDocsUploadFromUrl():void
		{
			var service:ScribdService = new ScribdService( API_KEY );
			service.secret = SECRET;
			service.addEventListener( ScribdResultEvent.DOCS_UPLOAD_FROM_URL, 
									  addAsync( onDocsUploadFromUrl, CALL_TIMEOUT ) );
			service.docs.uploadFromUrl( null );
		}
		
		private function onDocsUploadFromUrl( event:ScribdResultEvent ):void
		{
			assertTrue( "event.success == true", event.success );
		}

		//**************************************************************
		//
		// Tests for the "User" Method Group
		//
		//**************************************************************
		
		public function testUserLogin():void
		{
			var service:ScribdService = new ScribdService( API_KEY );
			service.addEventListener( ScribdResultEvent.USER_LOGIN, 
									  addAsync( onUserLogin, CALL_TIMEOUT ) );
			service.user.login( null, null );
		}
		
		private function onUserLogin( event:ScribdResultEvent ):void
		{
			assertTrue( "event.success == true", event.success );
		}
		
		public function testUserSignup():void
		{
			var service:ScribdService = new ScribdService( API_KEY );
			service.addEventListener( ScribdResultEvent.USER_SIGNUP, 
									  addAsync( onUserSignup, CALL_TIMEOUT ) );
			service.user.signup( null, null, null );
		}
		
		private function onUserSignup( event:ScribdResultEvent ):void
		{
			assertTrue( "event.success == true", event.success );
		}

	}

}
